package cn.lliiooll.papi;

import cn.lliiooll.mt.ShiFu;
import cn.lliiooll.mt.TuDi;
import me.clip.placeholderapi.PlaceholderAPI;
import me.clip.placeholderapi.PlaceholderHook;
import org.bukkit.OfflinePlayer;
import org.bukkit.entity.Player;

public class PapiHook extends PlaceholderHook {

    private static final String hook_name = "mentor";

    @Override
    public String onPlaceholderRequest(Player p, String i) {
        if(p == null){
            return null;
        }
        if (i.equalsIgnoreCase("mentor")) {
            return String.valueOf(new TuDi(p).getShiFu().getPlayer().getName());
        }
        if (i.equalsIgnoreCase("pupil")) {
            return String.valueOf(new ShiFu(p).getTuDi().getPlayer().getName());
        }

        return null;
    }

    public boolean hook() {
       return PlaceholderAPI.registerPlaceholderHook(hook_name, new PapiHook());
    }

    public static void unhook() {
        PlaceholderAPI.unregisterPlaceholderHook(hook_name);
    }

    public static String replacepapi(OfflinePlayer player, String x) {
        return PlaceholderAPI.setPlaceholders(player, x.replace("&", "§"));
    }
}
